package com.elinkway.infinitemovies.view;


import android.content.Context;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.elinkway.infinitemovies.bean.VideoDataBean;
import com.elinkway.infinitemovies.utils.MoviesConstant;
import com.elinkway.infinitemovies.utils.MoviesUtils;
import com.le123.ysdq.R;

public class IntroduceView extends LinearLayout {



    private TextView mPlayStarringBody;
    private TextView mPlayDirectorBody;
    private TextView mPlayStyleBody;
    private TextView mIntroTv;
    private TextView mPlayStarring;
    private LinearLayout mPlayStarringLay;
    private LinearLayout mPlayDirectorLay;
    private LinearLayout mPlayStyleLay;

    public IntroduceView(Context context) {
        super(context);
        initView(context);
    }

    public IntroduceView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    public IntroduceView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initView(context);
    }

    private void initView(Context context){
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        inflater.inflate(R.layout.introduce_layout, this);
        findViewById(R.id.body_lay).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if(icon != null){
                    setVisable(icon);
                }
            }
        });
        mPlayStarring = (TextView) findViewById(R.id.play_starring);
        mPlayStarringBody = (TextView) findViewById(R.id.play_starring_body);
        mPlayDirectorBody = (TextView) findViewById(R.id.play_director_body);
        mPlayStyleBody = (TextView) findViewById(R.id.play_style_body);
        mIntroTv = (TextView) findViewById(R.id.intro_tv);
        mPlayStarringLay = (LinearLayout) findViewById(R.id.play_starring_lay);
        mPlayDirectorLay = (LinearLayout) findViewById(R.id.play_director_lay);
        mPlayStyleLay = (LinearLayout) findViewById(R.id.play_style_lay);
    }


    public void setVideoDataBean(VideoDataBean mVideo){
        if (MoviesConstant.VT_ZONGYI.equals(mVideo.getVt())) {
            if(TextUtils.isEmpty(mVideo.getStarringname())){
                mPlayStarringLay.setVisibility(View.GONE);
            } else {
                mPlayStarringLay.setVisibility(View.VISIBLE);
                mPlayStarring.setText(R.string.video_starring_presenter_str);
                mPlayStarringBody.setText(mVideo.getStarringname());
            }
        } else {
            if(TextUtils.isEmpty(mVideo.getStarringname())){
                mPlayStarringLay.setVisibility(View.GONE);
            } else {
                mPlayStarringLay.setVisibility(View.VISIBLE);
                mPlayStarring.setText(R.string.video_starring_actor_str);
                mPlayStarringBody.setText(mVideo.getStarringname());
            }
        }
        String directorText = MoviesUtils.optString(mVideo.getDirectoryname(), "暂无");
        mPlayDirectorBody.setText(directorText);
        String categoryNameText = MoviesUtils.optString(mVideo.getCategoryname(), "暂无");
        mPlayStyleBody.setText(categoryNameText);
        String descriptionText = mVideo.getDescription().equals("") ? "简介: " + mVideo
                .getShortdesc() : "简介: " + mVideo.getDescription();
        mIntroTv.setText(descriptionText);
    }
    private ImageView icon;

    public void setVisable(ImageView mImageView){
        this.icon = mImageView;
        if(this.getVisibility() == View.VISIBLE){
            this.setVisibility(View.GONE);
            icon.setImageResource(R.drawable.video_detail_more2);
        } else {
            this.setVisibility(View.VISIBLE);
            icon.setImageResource(R.drawable.video_detail_more1);
        }
    }
}
